#ifndef RBT_PROFILE_PARSER
#define RBT_PROFILE_PARSER

#include "Object.h"
#include <limits>

RETURNCODE E_EMPTY_KEY   = -801;
RETURNCODE E_PARSE_ERROR = -802;

class Parser
{

	enum VALUE_TYPE
	{
		TYPE_SIGNED,
		TYPE_FOLAT,
		TYPE_VALUE
	};

	ctchar* now;
	ctchar* next;
	ctchar* token;
	ctchar* end;

	bool EndOfText();
	bool MoveNext();

    template<class T , class O >
	bool IsValueType( const O& value );

	bool IsValue(   ctchar& v ,  ctchar* p = 0);
	bool IsRange(   ctchar& lhs ,ctchar& rhs , ctchar* v);
	
	bool IsOperator(ctchar* v = 0);
	bool IsKeyword( ctchar* v = 0 );
	bool IsNumber(  ctchar* v = 0 );
	bool IsAllWord( ctchar* v = 0 );
	bool IsSpace(   ctchar* v = 0 );
	bool IsEndLine( ctchar* v = 0 );

	void  SkipSpace();
	int32 SkipEndLine();

	int32 ReadOper( string& op  );
	int32 ReadKey(  string& key );

	int32 ReadValue(     Object& object );
	int32 ReadKeyValue(  Object& object );
	int32 ReadArray(     Object& object );
	int32 ReadString(    Object& object );
	int32 AutoReadValue( Object& object );

public:

	int32 End();
	int32 ReadObject( string& keyName , string& opName , Object& valueObject );
	int32 Initialize( cstring& text );

};

template<class T , class O >
bool Parser::IsValueType( const O& value )
{
	if( value > (std::numeric_limits< T >::max)() )
		return false;
	if( value < (std::numeric_limits< T >::min)() )
		return false;
	return true;
}

#endif